<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

// 定义tabbar项
const tabs = [
  {
    name: 'home',
    title: 'AI直播',
    icon: 'live',
    path: '/',
  },
  {
    name: 'profile',
    title: '我的',
    icon: 'profile',
    path: '/profile',
  },
]

// 计算当前激活的tab
const activeTab = computed(() => {
  return route.path
})

// 切换tab
const switchTab = (path: string) => {
  router.push(path)
}
</script>

<template>
  <div class="tabbar">
    <div class="tabbar-item-box">
      <div
        v-for="tab in tabs"
        :key="tab.name"
        class="tabbar-item"
        :class="{ active: activeTab === tab.path }"
        @click="switchTab(tab.path)"
      >
        <div class="tabbar-icon" :class="tab.icon"></div>
        <div class="tabbar-title">{{ tab.title }}</div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100px;
  box-sizing: border-box;
  padding: 15px 16px;
  z-index: 100;
  .tabbar-item-box {
    background-color: #ffffff;
    display: flex;
    box-shadow: 0px 0px 15px 0px #00000014;
    opacity: 1;
    border-radius: 42.5px;
    height: 100%;
  }
  .tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;

    &.active {
      color: #006cff;

      .tabbar-icon {
        &.live {
          background-image: url('@/assets/images/tabbar/live-active.png');
        }

        &.profile {
          background-image: url('@/assets/images/tabbar/profile-active.png');
        }
      }
    }

    .tabbar-icon {
      width: 24px;
      height: 24px;
      margin-bottom: 2px;
      background-position: center;
      background-repeat: no-repeat;
      background-size: contain;

      &.live {
        background-image: url('@/assets/images/tabbar/live.png');
      }

      &.profile {
        background-image: url('@/assets/images/tabbar/profile.png');
      }
    }

    .tabbar-title {
      font-family: PingFang SC, PingFang SC;
      font-weight: 600;
      font-size: 10px;
    }
  }
}
</style>
